//
//  HMGroupTableViewCell.m
//  localLife
//
//  Created by Limonwei on 15/11/26.
//  Copyright © 2015年 heima. All rights reserved.
//

#import "HMGroupTableViewCell.h"
#import "HMGroupCollectionViewCell.h"

@interface HMGroupTableViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate>


@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *flowLayout;

@end

static NSString *ID = @"HMGroupCollectionViewCell";

@implementation HMGroupTableViewCell

- (void)awakeFromNib {
    // Initialization code
    
    [_collectionView registerNib:[UINib nibWithNibName:ID bundle:nil] forCellWithReuseIdentifier:ID];
    
    _collectionView.backgroundColor = [UIColor whiteColor];
    
    _collectionView.scrollEnabled = NO;
    
    _collectionView.showsHorizontalScrollIndicator = NO;
    
    _collectionView.showsVerticalScrollIndicator = NO;

}

//设置frame
-(void)layoutSubviews{
    
    [super subviews];
    
    _flowLayout.itemSize = CGSizeMake(self.frame.size.width/4, self.frame.size.height/2);
    
    _flowLayout.minimumInteritemSpacing = 0;
    
    _flowLayout.minimumLineSpacing = 0;
    
    _flowLayout.sectionInset = UIEdgeInsetsZero;
    
}

-(void)setList:(HMGroupList *)list{
    
    _list = list;
    
    //刷新数据
    
    [_collectionView reloadData];
    
}


-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return _list.list.count;
}


-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    HMGroupCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
    
    //模型赋值
    cell.model = _list.list[indexPath.row];
    
    
    return cell;
    
    
}


-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    [_delegate didItemSelected:indexPath.row];
    
}


@end














